#pragma once
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string>

class InetAddr
{
public:
    InetAddr(const struct sockaddr_in &addr):_addr(addr)
    {
        _ip = inet_ntoa(addr.sin_addr);
        _port = ntohs(addr.sin_port);
    }

    std::string ip()
    {
        return _ip;
    }

    uint16_t port()
    {
        return _port;
    }

    bool operator==(const InetAddr &addr)
    {
        if (_ip == addr._ip && _port == addr._port)
        {
            return true;
        }
        return false;
    }

    struct sockaddr_in& Addr()
    {
        return _addr;
    }

private:
    struct sockaddr_in _addr;
    std::string _ip;
    uint16_t _port;
};